<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The Sequence interface</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="ds-hashable.hash.html">« Ds\Hashable::hash</a></li>
      <li style="float: right;"><a href="ds-sequence.allocate.html">Ds\Sequence::allocate »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.ds.html">Data Structures</a></li>
    <li>The Sequence interface</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.ds-sequence" class="reference">

 <h1 class="title">The Sequence interface</h1>
 

 <div class="partintro"><p class="verinfo">(No version information available, might only be in Git)</p>


  <div class="section" id="ds-sequence.intro">
   <h2 class="title">简介</h2>
   <p class="para">
        A Sequence describes the behaviour of values arranged in a single, linear dimension.
        Some languages refer to this as a &quot;List&quot;. It’s similar to an array that uses
        incremental integer keys, with the exception of a few characteristics:
        <ul class="simplelist">
            <li class="member">Values will always be indexed as [0, 1, 2, …, size - 1].</li>
            <li class="member">Only allowed to access values by index in the range [0, size - 1].</li>
        </ul>
    </p>
    <p class="para">
        Use cases:
        <ul class="simplelist">
            <li class="member">Wherever you would use an array as a list (not concerned with keys).</li>
            <li class="member">A more efficient alternative to
                <span class="classname"><a href="class.spldoublylinkedlist.html" class="classname">SplDoublyLinkedList</a></span> and
                <span class="classname"><a href="class.splfixedarray.html" class="classname">SplFixedArray</a></span>.
            </li>
        </ul>
   </p>
  </div>


  <div class="section" id="ds-sequence.synopsis">
   <h2 class="title">接口摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">

    <span class="ooclass"><span class="modifier">class</span> <strong class="classname">Ds\Sequence</strong></span>
    <span class="oointerface"><span class="modifier">implements</span>  <strong class="interfacename">Ds\Collection</strong></span><span class="oointerface">,  <a href="class.arrayaccess.html" class="interfacename">ArrayAccess</a></span> {</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.allocate.html" class="methodname">allocate</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$capacity</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.apply.html" class="methodname">apply</a></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.capacity.html" class="methodname">capacity</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.contains.html" class="methodname">contains</a></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">...$values</code></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.filter.html" class="methodname">filter</a></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="class.ds-sequence.html" class="type Ds\Sequence">Ds\Sequence</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.find.html" class="methodname">find</a></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.first.html" class="methodname">first</a></span>(): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.get.html" class="methodname">get</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$index</code></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.insert.html" class="methodname">insert</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$index</code></span>, <span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">...$values</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.join.html" class="methodname">join</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$glue</code><span class="initializer"> = ?</span></span>): <span class="type">string</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.last.html" class="methodname">last</a></span>(): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.map.html" class="methodname">map</a></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>): <span class="type"><a href="class.ds-sequence.html" class="type Ds\Sequence">Ds\Sequence</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.merge.html" class="methodname">merge</a></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$values</code></span>): <span class="type"><a href="class.ds-sequence.html" class="type Ds\Sequence">Ds\Sequence</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.pop.html" class="methodname">pop</a></span>(): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.push.html" class="methodname">push</a></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">...$values</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.reduce.html" class="methodname">reduce</a></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>, <span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$initial</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.remove.html" class="methodname">remove</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$index</code></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.reverse.html" class="methodname">reverse</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.reversed.html" class="methodname">reversed</a></span>(): <span class="type"><a href="class.ds-sequence.html" class="type Ds\Sequence">Ds\Sequence</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.rotate.html" class="methodname">rotate</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$rotations</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.set.html" class="methodname">set</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$index</code></span>, <span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.shift.html" class="methodname">shift</a></span>(): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.slice.html" class="methodname">slice</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$index</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$length</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="class.ds-sequence.html" class="type Ds\Sequence">Ds\Sequence</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.sort.html" class="methodname">sort</a></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$comparator</code><span class="initializer"> = ?</span></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.sorted.html" class="methodname">sorted</a></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$comparator</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="class.ds-sequence.html" class="type Ds\Sequence">Ds\Sequence</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.sum.html" class="methodname">sum</a></span>(): <span class="type"><span class="type">int</span>|<span class="type">float</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">abstract</span> <span class="modifier">public</span> <span class="methodname"><a href="ds-sequence.unshift.html" class="methodname">unshift</a></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$values</code><span class="initializer"> = ?</span></span>): <span class="type"><span class="type void">void</span></span></div>

   }</div>


  </div>

  <div class="section">
   <h2 class="title">更新日志</h2>
   <p class="para">
    <table class="doctable informaltable">
     
      <thead>
       <tr>
        <th>版本</th>
        <th>说明</th>
       </tr>

      </thead>

      <tbody class="tbody">
       <tr>
        <td>PECL ds 1.3.0</td>
        <td>
         The interface now extends <span class="classname"><a href="class.arrayaccess.html" class="classname">ArrayAccess</a></span>.
        </td>
       </tr>

      </tbody>
     
    </table>

   </p>
  </div>

 </div>

 






























































































































































































<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="ds-sequence.allocate.html">Ds\Sequence::allocate</a> — Allocates enough memory for a required capacity</li><li><a href="ds-sequence.apply.html">Ds\Sequence::apply</a> — Updates all values by applying a callback function to each value</li><li><a href="ds-sequence.capacity.html">Ds\Sequence::capacity</a> — Returns the current capacity</li><li><a href="ds-sequence.contains.html">Ds\Sequence::contains</a> — Determines if the sequence contains given values</li><li><a href="ds-sequence.filter.html">Ds\Sequence::filter</a> — Creates a new sequence using a callable to
    determine which values to include</li><li><a href="ds-sequence.find.html">Ds\Sequence::find</a> — Attempts to find a value's index</li><li><a href="ds-sequence.first.html">Ds\Sequence::first</a> — Returns the first value in the sequence</li><li><a href="ds-sequence.get.html">Ds\Sequence::get</a> — Returns the value at a given index</li><li><a href="ds-sequence.insert.html">Ds\Sequence::insert</a> — Inserts values at a given index</li><li><a href="ds-sequence.join.html">Ds\Sequence::join</a> — Joins all values together as a string</li><li><a href="ds-sequence.last.html">Ds\Sequence::last</a> — Returns the last value</li><li><a href="ds-sequence.map.html">Ds\Sequence::map</a> — Returns the result of applying a callback to each value</li><li><a href="ds-sequence.merge.html">Ds\Sequence::merge</a> — Returns the result of adding all given values to the sequence</li><li><a href="ds-sequence.pop.html">Ds\Sequence::pop</a> — Removes and returns the last value</li><li><a href="ds-sequence.push.html">Ds\Sequence::push</a> — Adds values to the end of the sequence</li><li><a href="ds-sequence.reduce.html">Ds\Sequence::reduce</a> — Reduces the sequence to a single value using a callback function</li><li><a href="ds-sequence.remove.html">Ds\Sequence::remove</a> — Removes and returns a value by index</li><li><a href="ds-sequence.reverse.html">Ds\Sequence::reverse</a> — Reverses the sequence in-place</li><li><a href="ds-sequence.reversed.html">Ds\Sequence::reversed</a> — Returns a reversed copy</li><li><a href="ds-sequence.rotate.html">Ds\Sequence::rotate</a> — Rotates the sequence by a given number of rotations</li><li><a href="ds-sequence.set.html">Ds\Sequence::set</a> — Updates a value at a given index</li><li><a href="ds-sequence.shift.html">Ds\Sequence::shift</a> — Removes and returns the first value</li><li><a href="ds-sequence.slice.html">Ds\Sequence::slice</a> — Returns a sub-sequence of a given range</li><li><a href="ds-sequence.sort.html">Ds\Sequence::sort</a> — Sorts the sequence in-place</li><li><a href="ds-sequence.sorted.html">Ds\Sequence::sorted</a> — Returns a sorted copy</li><li><a href="ds-sequence.sum.html">Ds\Sequence::sum</a> — Returns the sum of all values in the sequence</li><li><a href="ds-sequence.unshift.html">Ds\Sequence::unshift</a> — Adds values to the front of the sequence</li></ul>
</div>
</div></div></body></html>